﻿<%@ Page Language="C#" AutoEventWireup="true" Codebehind="AddCourse.aspx.cs" Inherits="LabMS.Web.BaseData.AddCourse" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>新增课程数据</title>
    <link type="text/css" rel="stylesheet" href="../style/screen.css" />
    <!--[if lte IE 6]>
    <link type="text/css" rel="stylesheet" href="../style/ie6.css" />
    <![endif]-->
    <!--[if lte IE 7]>
    <link type="text/css" rel="stylesheet" href="../style/ie7.css" />
    <![endif]-->
</head>
<body class="mainBody">
    <form id="uiForm" runat="server">
        <div class="main">
            <div id="pageInfo" class="clearfix">
                <div class="title">
                    <label>
                        课程数据</label>
                    &gt;
                    <label>
                        新增课程数据</label>
                </div>
            </div>
        </div>
        <div class="main">
            <input id="btnSubmit" type="button" value="保存" class="button" />
            <input type="button" class="button" id="btnCanel" value="取消" onclick="window.close();" />
            <table border="0" cellpadding="4" cellspacing="0">
                <tr>
                    <td>
                        <label class="itemTitle">
                            课 程 号</label></td>
                    <td>
                        <asp:TextBox ID="tbCode" ToolTip="课程号" runat="server"></asp:TextBox></td>
                </tr>
                <tr>
                    <td>
                        <label class="itemTitle">
                            课程属性</label></td>
                    <td>
                        <asp:DropDownList ID="ddlType" runat="server">
                            <asp:ListItem Text="一般课程" Value="一般课程"></asp:ListItem>
                            <asp:ListItem Text="包含实验(上机)课程" Value="包含实验(上机)课程"></asp:ListItem>
                            <asp:ListItem Text="独立实验课程" Value="独立实验课程"></asp:ListItem>
                            <asp:ListItem Text="实习(实训)" Value="实习(实训)"></asp:ListItem>
                            <asp:ListItem Text="课程设计" Value="课程设计"></asp:ListItem>
                        </asp:DropDownList></td>
                </tr>
                <tr>
                    <td>
                        <label class="itemTitle">
                            课程名称</label></td>
                    <td>
                        <asp:TextBox ID="tbName" ToolTip="课程名称 - 必填项,长度为1到50之间!" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        <label class="itemTitle">
                            英文名称</label></td>
                    <td>
                        <asp:TextBox ID="tbnEnglishName" ToolTip="英文名称 - 必填项,长度为1到50之间!" runat="server"></asp:TextBox></td>
                </tr>
                <tr>
                    <td>
                        <label class="itemTitle">
                            实验学时</label></td>
                    <td>
                        <asp:TextBox ID="tbHour" ToolTip="实验学时 - 必填项,必须为整数" runat="server"></asp:TextBox></td>
                </tr>
                <tr>
                    <td>
                        <label class="itemTitle">
                            课 &nbsp;&nbsp; 时</label></td>
                    <td>
                        <asp:TextBox ID="tbCourseHouse" runat="server" ToolTip="课时-必填项，必须为整数"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        <label class="itemTitle">
                            面向专业</label></td>
                    <td>
                        <table>
                            <tr>
                                <td>
                                    <a href="#" id="btnAddPro">添加专业</a>
                                </td>
                            </tr>
                            <tr>
                                <td style="width: 300px">
                                    <table id="GvAddPro" cellpadding="2" cellspacing="0" class="infoTable" border="0">
                                        <tbody>
                                            <tr>
                                                <th>
                                                    <label class="itemTitle">
                                                        专业号</label></th>
                                                <th>
                                                    <label class="itemTitle">
                                                        专业名称</label></th>
                                                <th>
                                                    <label class="itemTitle">
                                                        删除</label></th>
                                            </tr>
                                        </tbody>
                                    </table>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </div>
    </form>

    <script type="text/javascript" src="../js/jQuery/jquery-1.3.1.js"></script>

    <script type="text/javascript" src="../js/jQuery/jquery.tooltip.js"></script>

    <script type="text/javascript" src="../js/jQuery/jquery.bgiframe.js"></script>

    <script type="text/javascript" src="../js/jQuery/jquery.validate.js"></script>

    <script type="text/javascript" src="../js/jQuery/jquery.json-1.3.min.js"></script>

    <script type="text/javascript" src="../js/site.js"></script>

    <script type="text/javascript">
        
    $(function(){
        /* 获取当前课程有哪些专业 */  
        /*$.getJSON(
            "GetCourseMajors.ashx",
            {ID: $("#tbCode").val()},
            function(data){
                if (data.error) {
                    alert('');
                } else {
                    for(var i = 0; i < data.Majors.length; i++){
                        major = data.Majors[i];
                    
                        $("<tr><td></td><td align='right'></td><td></td></tr>")
                            .find("td:first")
                            .html(major.ID)
                        .end()
                            .find("td:nth-child(2)")
                            .prepend(major.Name)
                        .end()
                            .find("td:nth-child(3)")
                            .append(
                                $("<a href='#'>删除</a>")
                                .click(function(e){
                                    $(this).parent().parent().remove();
                                    e.preventDefault();
                                })
                            )
                        .end()
                        .appendTo("#GvAddPro");
                }
            }
        );*/
        
        /* 添加专业 */
        $("#btnAddPro").click(function(e){
            $("<tr><td></td><td align='right'><input type='button' class='button' style='width: 40px' value='...' /></td><td><a href='#'>删除</a></td></tr>")
                .find("input")
                .click(function(){
                    showAllMajors($(this).parent().parent());
                })
            .end()
                .find("a")
                .click(function(){
                    $(this).parent().parent().remove();
                    e.preventDefault();
                })
            .end()
            .appendTo("#GvAddPro");
        });
        
        /* 页面验证 */
        $("#uiForm").validate({
            rules: {
                    tbName: {
                        required: true,
                        maxlength: 50
                    },
                    tbnEnglishName: {
                        required: true,
                        maxlength: 50
                    },
                    tbHour: {
                        required: true,
                        number: true
                    },
                    tbCourseHouse:{
                        required:true,
                        number:true
                    }
                },
                messages: {
                    tbName: {
                        required: "请输入课程名称",
                        maxlength: "课程名称长度不能超过50！"
                    },
                    tbnEnglishName: {
                        required: "请输入英文名称!",
                        maxlength: "课程的英文名称长度不能超过50!"
                    },
                    tbHour: {
                        required: "课程学时不能为空",
                        number: "课程学时必须为整数"
                    },
                    tbCourseHouse:{
                        required:"课时不能为空",
                        number:"课时必须为整数"
                    }
                }
        });
        
        /* 保存 */
        $("#btnSubmit").click(function(){
            if (!$("#uiForm").valid()) {return;}
            
            var c = {};
            c.Code = $("#tbCode").val();
            c.Name = $("#tbName").val();
            c.EnglishName = $("#tbnEnglishName").val();
            c.Hour = $("#tbHour").val();
            c.Type = $("#ddlType").val();
            c.CourseHouse=$("#tbCourseHouse").val();
            c.Majors = [];//定义一个JSON对象
            
           $("#GvAddPro").find("tr").not(":first").each(function(index, domElem){
                var major = {};//定义一个JSON对象
                major.ID = $(this).find("td:first").html();
                major.Name = $(this).find("td:nth-child(2)").html();
                
                if (major.ID.length > 0) {
                    c.Majors.push(major);
                }
           });
           //传值，实现保存
           $.post(               
                "SaveCource.ashx",
                $.toJSON(c),
                function(data, status) {
                    if (data.success) {
                        alert('添加成功');
                    } else if(data.error) {
                        alert(data.msg);
                    }
                },
                "json"
           );
        });
    });
    
    /*function Person(name, age){
       this.name = name;
       this.age = age;
       
       function getName(){return this.name;}
    }
    
    Person.prototype = new Object();
    Person.prototype.constructor = Person;
    
    var Girl = function(){}
    Girl.prototype = new Person();
    
    var p = new Person('s', 1);
    var n = p.getName();*/
    
    function showAllMajors(trJQuery) {
       var ret = window.showModalDialog("AddClassChooseMajor.aspx", window);
        
        if (ret != null){
            var contained = false;
            $("#GvAddPro").find("tr").not(":first").each(function(){
                if ($(this).find("td:first").html() == ret[0]){
                    contained = true;
                    return false;
                }
            });
            
            if (contained) {return;}
            
            trJQuery.find("td:first").html(ret[0])
            .end().find("td:nth-child(2)").text(ret[1]);
        }
    }
    
    </script>

</body>
</html>
